 <?php
/*
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License

  Featured Products V1.1
  Displays a list of featured products, selected from admin
  For use as an Infobox instead of the "New Products" Infobox
*/
?>
<!-- featured_products //-->
<?php
echo '<table cellspacing="0" cellpadding="0" width="100%" border="0">';
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
  table_image_border_top_main(false, false, TABLE_HEADING_FEATURED_PRODUCTS);
} else {
echo TABLE_HEADING_FEATURED_PRODUCTS;
}
// EOF: Lango Added for template MOD


 if(FEATURED_PRODUCTS_DISPLAY == true)
 {
  $featured_products_category_id = $new_products_category_id;
  $cat_name_query = tep_db_query("select categories_name from categories_description where categories_id = '" . $featured_products_category_id . "' limit 1");
  $cat_name_fetch = tep_db_fetch_array($cat_name_query);
  $cat_name = $cat_name_fetch['categories_name'];
  $info_box_contents = array();

  if ( (!isset($featured_products_category_id)) || ($featured_products_category_id == '0') ) {
    $info_box_contents[] = array('align' => 'left', 'text' => TABLE_HEADING_FEATURED_PRODUCTS);
    $featured_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, s.status as specstat, s.specials_new_products_price, p.products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id left join " . TABLE_FEATURED . " f on p.products_id = f.products_id where p.products_status = '1' and f.status = '1' order by rand() DESC limit " . MAX_DISPLAY_FEATURED_PRODUCTS);
  } else {
    $info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_FEATURED_PRODUCTS_CATEGORY, $cat_name));
    $featured_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, s.status as specstat, s.specials_new_products_price, p.products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c left join " . TABLE_FEATURED . " f on p.products_id = f.products_id where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $featured_products_category_id . "' and p.products_status = '1' and f.status = '1' order by rand() DESC limit " . MAX_DISPLAY_FEATURED_PRODUCTS);
  }

  $row = 0;
  $col = 0;
  $num = 0;
  $column=0;
  $rows = 0;
  while ($featured_products = tep_db_fetch_array($featured_products_query)) {
    $num ++;
	if ($num == 1) {

echo ' <table cellspacing="0" cellpadding="0" width="100%" border="0" class="product">';
    }
	
	

  $featured_query_description = tep_db_query("select products_description  from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$featured_products['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

  $featured_description = tep_db_fetch_array($featured_query_description);
  $featured_products['products_name'] = tep_get_products_name($featured_products['products_id']);

  $cat_name_query = tep_db_query("select categories_id from products_to_categories where products_id = '" . (int)$featured_products['products_id'] . "' limit 1");
  $cat_id = tep_db_fetch_array($cat_name_query);
  $cat_name_query = tep_db_query("select categories_name from categories_description where categories_id  = '" . (int)$cat_id['categories_id'] . "' limit 1");
  $cat_name = tep_db_fetch_array($cat_name_query);


	$r_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products['products_id']) . '">' . $featured_products['products_name'] . '</a>';
	
    $r_pic = tm_image_border('<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $featured_products['products_image'], $featured_products['products_name'], MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT) . '</a>');
 
	if (tep_get_products_special_price($featured_products['products_id'])) {
		  $r_price = '<s>' .  $currencies->display_price($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id'])) . '</s>' . PRICE_SEPARATOR . '<span class="productSpecialPrice">' . $currencies->display_price(tep_get_products_special_price($featured_products['products_id']), tep_get_tax_rate($featured_products['products_tax_class_id'])) . '</span>';

		} else {
		  $r_price = '<span class="productSpecialPrice">' . $currencies->display_price($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id'])) . '</span>';
		}
		
    $r_desc = substr($featured_description['products_description'],0, MAX_DESC_MODULE).'...';
		
	$r_view = '<a href="' . tep_href_link('product_info.php','products_id=' . $featured_products['products_id']) . '">' .tep_image_button('button_details.gif').'</a>';

	$r_buy = '<a href="'.tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $featured_products['products_id']).'">' .tep_image_button('button_in_cart.gif').'</a>';


echo tep_list_products_row ($r_pic, $r_name, $r_price, $r_desc, $r_view, $r_buy);


      $column ++;
      if ($column >= COLUMN_COUNT) {
        $row ++;
        $column = 0;
      }
    }



  if($num) {

//      new contentBox($info_box_contents);

  echo '</table>';


  }
 } else // If it's disabled, then include the original New Products box
 {
   include (DIR_WS_MODULES . FILENAME_NEW_PRODUCTS);
 }
 
if (MAIN_TABLE_BORDER == 'yes'){
  table_image_border_bottom_main(false, false, '');
}

  echo '</table>';
?>

<!-- featured_products_eof //-->
